<?php
declare(strict_types=1);

namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use App\Middleware\WebApiMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\UserService\AccountService;
use Hyperf\Di\Annotation\Inject;

/**
 * 用户账户
 * @author huj
 * @Controller(prefix="/webapi/v1/account")
 * @Middleware(WebApiMiddleware::class)
 */
class AccountController extends AbstractController
{
    /**
     * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象
     * @Inject()
     * @var AccountService
     */
    protected $accountService;

    /**
     * 个人中心信息
     * @RequestMapping(path="index", methods="post")
     */
    public function index(RequestInterface $request)
    {
        return $this->accountService->memberAccount(
            $request->getAttribute('cid'),
            $request->getAttribute('mnid'),
            $request->getAttribute('mn_sid'),
            $request->getAttribute('mid')
        );
    }

    /**
     * 积分明细---已废弃
     * @RequestMapping(path="pointslog", methods="get,post")
     */
    public function pointslog(RequestInterface $request)
    {
        return $this->accountService->pointsLog(
            $request->getAttribute('cid'),
            $request->getAttribute('mnid'),
            $request->getAttribute('mn_sid'),
            $request->getAttribute('mid'),
            $request->getParsedBody()
            );
    }

    /**
     * 新积分明细
     * @RequestMapping(path="goodsPointsLog", methods="get,post")
     */
    public function goodsPointsLog(RequestInterface $request)
    {
        return $this->accountService->goodsPointsLog(
            $request->getAttribute('cid'),
            $request->getAttribute('mnid'),
            $request->getAttribute('mn_sid'),
            $request->getAttribute('mid'),
            $request->getParsedBody()
            );
    }

    /**
     * 新积分规则
     * @RequestMapping(path="pointsRule", methods="get,post")
     */
    public function pointsRule(RequestInterface $request)
    {
        return $this->accountService->pointsRule(
            $request->getAttribute('cid'),
            $request->getAttribute('mnid'),
            $request->getAttribute('mn_sid'),
            $request->getAttribute('mid'),
            $request->getParsedBody()
            );
    }
}